package org.extremengine.shape;

import org.extremengine.common.Point;
import org.extremengine.common.Velocity;

/**
 * 线段
 * @author yuxing
 *
 */
public class LineSegment extends Shape {
	private Point p1;
	private Point p2;

	public LineSegment(Point p1, Point p2) {
		super();
		this.p1 = p1;
		this.p2 = p2;
	}

	@Override
	public Point getBarycenter() {
		return p1.centerPoint(p2);
	}

	@Override
	public void transform(double deltax, double deltay) {
		p1.setX(p1.x + deltax);
		p1.setY(p1.y + deltay);
		p2.setX(p2.x + deltax);
		p2.setY(p2.y + deltay);
	}

	@Override
	public void transform(Velocity v, long timePeirod) {
		double deltax = (v.getSpeedx() * timePeirod) / 1000;
		double deltay = (v.getSpeedy() * timePeirod) / 1000;
		transform(deltax, deltay);
	}

	public Point getP1() {
		return p1;
	}

	public void setP1(Point p1) {
		this.p1 = p1;
	}

	public Point getP2() {
		return p2;
	}

	public void setP2(Point p2) {
		this.p2 = p2;
	}

	@Override
	public Shape clone() {
		return new LineSegment(new Point(this.p1.x, this.p1.y), new Point(this.p2.x, this.p2.y));
	}
	
}
